package start.demo01.datatype.json.entity.editor;

import start.demo01.datatype.json.interfaces.Editor;
import start.demo01.datatype.json.pool.CacheMap;

import java.util.Iterator;
import java.util.LinkedList;

//过滤器
public class EditorChain extends LinkedList<Editor> {

    public static EditorChain builder() {
        return new EditorChain();
    }

    public EditorChain chain(Editor editor) {
        add(editor);
        return this;
    }

    public EditorChain(Editor... editors) {
        for (Editor editor : editors) {
            add(editor);
        }
    }

    public void execute(CacheMap map) {
        Iterator<Editor> iterator = iterator();
        while (iterator.hasNext()) {
            Editor next = iterator.next();
            next.setMap(map);
            next.editor();
        }
    }
}
